package cn.itcast.com.IO.zifuliu.introduction;


import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.SortedMap;

//编解码只针对字符或文本数据，
//
public class demo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        System.out.println(Charset.availableCharsets());
        String name  = "你好";
        //gbk编码
        byte[] bytes = name.getBytes("gbk");
        System.out.println(Arrays.toString(bytes));
        //gbk解码
        String gbkstr = new String(bytes,0,bytes.length,"gbk");
        System.out.println(gbkstr);

        //utf-8编码
        byte[] bytes1 = name.getBytes("utf-8");
        System.out.println(Arrays.toString(bytes1));
        //utf-8解码
        String utfstr = new String(bytes1,0,bytes1.length,"utf-8");
        System.out.println(utfstr);


    }
}
